from MinConflicts import MinConflicts
from GraphColorStateManager import GraphColorStateManager

class GraphColorMC(MinConflicts):

	#each specific problem has it's own constrains that are added to the general problem
	def __init__(self, k):
		self.k=k
		super(GraphColorMC, self).__init__()
	
	def minConflicts(self):
		self.initStateManager(self.k)
		#calling the parent class method
		return super(GraphColorMC, self).minConflicts()
		
	def initStateManager(self, k):
		self.localStateManager = GraphColorStateManager(k)
		self.localStateManager.generateInitState()
		
	def conflicts(self, var, state):
		copy_state = list(state)
		currentValue = self.localStateManager.evalutateState(copy_state)
		for i in range(1,self.localStateManager.kColors):
			copy_state[var] = i
			if currentValue > self.localStateManager.evalutateState(copy_state):
				currentValue = i
		return currentValue
		
	def conflictedVariables(self, state):
		conflicted = []
		for i in range(len(state)):
			if not state[i] == 0:
				for j in self.localStateManager.graph:
					if (state[j[0]] == state[j[1]]):
						if j[0] not in conflicted:
							conflicted+=[j[0]]
						if j[1] not in conflicted:
							conflicted+=[j[1]]
		return conflicted